package com.eastedu.report.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * The type Pattern util.
 *
 * @author superman
 */
public interface PatternUtil {
    /**
     * The Pattern.
     */
    Pattern PATTERN_NUMBER = Pattern.compile("\\d+");

    /**
     * Extract number Integer.
     *
     * @param input the input
     * @return the integer
     */
    static Integer extractNumberInteger(String input) {
        return Integer.parseInt(extractNumberString(input));
    }

    /**
     * 提取数字
     *
     * @param input the input
     * @return the string
     */
    static String extractNumberString(String input) {
        Matcher matcher = PATTERN_NUMBER.matcher(input);
        StringBuilder builder = new StringBuilder();
        // 遍历匹配结果
        while (matcher.find()) {
            String number = matcher.group();
            builder.append(number);
        }
        return builder.toString();
    }
}
